package nxu.it.movieapi.service.pg;

import nxu.it.api.model.Cast;
import nxu.it.api.model.CastRole;
import nxu.it.api.model.Filmography;
import nxu.it.api.service.MovieCastService;
import nxu.it.movieapi.service.pg.dao.MovieCastDao;
import nxu.it.movieapi.service.pg.entity.CastEntity;
import nxu.it.movieapi.service.pg.entity.FilmographyEntity;
import nxu.it.movieapi.service.pg.mapper.MovieCastMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.validation.constraints.NotNull;
import java.util.List;

@Component
public class MovieCastServicePgImpl implements MovieCastService {
    @Autowired
    MovieCastDao movieCastDao;

    @Autowired
    MovieCastMapper movieCastMapper;

    @Override
    public List<Cast> findCastByMovieId(@NotNull Integer movieId) {
        List< CastEntity > castEntityList=movieCastDao.findCastByMovieId(movieId);
        return movieCastMapper.fromEntityList(castEntityList);
    }

    @Override
    public List<Cast> findCastByMovieIdAndRole(@NotNull Integer movieId, @NotNull CastRole role) {
        List< CastEntity > castEntityList=movieCastDao.findCastByMovieIdAndRole(movieId,role);
        return movieCastMapper.fromEntityList(castEntityList);
    }

    @Override
    public List<Cast> findActorsByMovieId(@NotNull Integer movieId) {
        List< CastEntity > castEntityList=movieCastDao.findActorsByMovieId(movieId);
        return movieCastMapper.fromEntityList(castEntityList);

    }

    @Override
    public List<Filmography> findMoviesByStaffId(@NotNull Integer staffId) {
        List<FilmographyEntity> filmographyEntityList = movieCastDao.findMoviesByStaffId(staffId);

        return movieCastMapper.toFilmographyList(filmographyEntityList);
    }

    @Override
    public List<Filmography> findMoviesByStaffIdAndRole(@NotNull Integer staffId, @NotNull CastRole role) {

        List<FilmographyEntity> filmographyEntityList = movieCastDao.findMoviesByStaffIdAndRole(staffId,role);

        return movieCastMapper.toFilmographyList(filmographyEntityList);

    }

    @Override
    public List<Filmography> findActedMoviesByStaffId(@NotNull Integer staffId) {
        List<FilmographyEntity> filmographyEntityList = movieCastDao.findActedMoviesByStaffId(staffId);

        return movieCastMapper.toFilmographyList(filmographyEntityList);
    }

    @Override
    public List<Filmography> findDirectedMoviesByStaffId(@NotNull Integer staffId) {
        List<FilmographyEntity> filmographyEntityList = movieCastDao.findDirectedMoviesByStaffId(staffId);

        return movieCastMapper.toFilmographyList(filmographyEntityList);

    }
}
